package com.myteam.fugaocrm.task;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.myteam.fugaocrm.common.ApplicationContextAware;
import com.myteam.fugaocrm.modle.FgProject;
import com.myteam.fugaocrm.modle.FgTask;
import com.myteam.fugaocrm.sqldb.mapper.FgProjectMapper;
import com.myteam.fugaocrm.sqldb.mapper.FgRemindMessageMapper;
import com.myteam.fugaocrm.sqldb.mapper.FgTaskMapper;

/**
 * 售前超过签约时间提醒
 * @author BZX
 *
 */
public class RemindSign {

	private FgTaskMapper fgTaskMapper = (FgTaskMapper) ApplicationContextAware.getApplicationContext().getBean(FgTaskMapper.class);
	private FgProjectMapper fgProjectMapper = (FgProjectMapper) ApplicationContextAware.getApplicationContext().getBean(FgProjectMapper.class);
	private FgRemindMessageMapper fgRemindMessageMapper = (FgRemindMessageMapper) ApplicationContextAware.getApplicationContext().getBean(FgRemindMessageMapper.class);
	
	public void work() {
		try {
        	//批量查询任务
        	List<FgTask> taskList = fgTaskMapper.all();
          
        	//依次循环执行任务
        	for(FgTask task : taskList) {
        		//售前日志
        		if(task.getTaskId() == 6 && task.getIsDelete() == 0) {
        			
        			List<FgProject> list = fgProjectMapper.selectListByState(1);//售前的全部数据
        			
        			//删除数据
    				fgRemindMessageMapper.deleteRemindByTypeId(6);
        			
        			//处理新增
        			for(FgProject temp : list) {
        				if(temp.getSignDate().getTime() < new Date().getTime()) {
            				Map<String, Object> param = new HashMap<String,Object>();
            				param.put("typeId", 6);
            				param.put("projectId", temp.getProjectId());
            				param.put("remindContent", "【" + temp.getProjectName() + "】项目签订日期过期");
            				fgRemindMessageMapper.insertSign(param);
        				}
        			}
        		}
        	}
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
}
